package com.alibaba.tesst;


import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;

import javax.sql.DataSource;

import com.alibaba.druid.pool.DruidDataSource;

public class AA {
	public static DataSource getDataSource1() throws Exception{
		DruidDataSource dataSource1 = new DruidDataSource();
		dataSource1.setDriverClassName("com.mysql.jdbc.Driver");
		dataSource1.setUrl("jdbc:mysql://127.0.0.1:3306/account?useUnicode=true&characterEncoding=utf-8&useSSL=false");
		dataSource1.setUsername("root");
		dataSource1.setPassword("123456");
//		dataSource1.addFilters("stat");
		return dataSource1;
	}
	
	public static void main(String[] args) throws SQLException, Exception {
		final String sql = "select * from money";
		
		for (int i = 0; i < 5; i++) {
			new Thread(new Runnable() {
				@Override
				public void run() {
					try {
						Connection conn = getDataSource1().getConnection();
						StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
				        for (StackTraceElement ele : stackTrace) {
				            System.out.println(ele);
				        }
						PreparedStatement preparedStatement = conn.prepareStatement(sql);
						ResultSet re = preparedStatement.executeQuery();
						while(re.next()) {
							System.out.println(re.getDouble("money"));
							System.out.println(re.getString("name"));
							System.out.println(re.getInt("id"));
						}
						
						preparedStatement.close();
						conn.close();
					} catch (Exception e) {
						e.printStackTrace();
					}
				}

			}, "get()线程" + (i+1)).start();
		}
		
	}
}
